<template>
  <header>
    <div class="flex justify-around items-center gap-4 h-12 sm:h-16 md:h-18 header-bg">
      <router-link :to="`/bbs`" class="h-full px-6 z-10">
        <div class="logo">
          <img :src="logo" alt="">
        </div>
      </router-link>

      <div class="flex-1 flex justify-between items-center z-10">
        <!-- 导航栏 -->
        <nav class=" hidden md:flex items-center md:h-18 h-18 ">
          <RouterLink :to="`/bbs`" class="nav_normal" active-class="nav_active">
            <div class="text-sm md:text-base lg:text-lg xl:text-2xl bold">综合</div>
          </RouterLink>
          <RouterLink :to="`/bbs/strategy`" class="nav_normal" active-class="nav_active">
            <div class="text-sm md:text-base lg:text-xl xl:text-2xl bold">攻略</div>
          </RouterLink>
          <RouterLink :to="`/bbs/information`" class="nav_normal " active-class="nav_active">
            <div class="text-sm md:text-base lg:text-lg xl:text-2xl bold">资讯</div>
          </RouterLink>
          <RouterLink :to="`/bbs/topic`" class="nav_normal" active-class="nav_active">
            <div class="text-sm md:text-base lg:text-lg xl:text-2xl bold">话题</div>
          </RouterLink>
        </nav>
        <div class="block md:hidden  i-carbon-menu" @click="isShow = true"></div>
        <!-- 搜索框 -->
        <div class="inputBox">
          <input class="search-input" v-model="searchStr" type="text" placeholder="搜索" @keyup.enter="searchTopic(searchStr)">
          <div class="search"></div>
        </div>
      </div>

      <div class="flex justify-between items-center  h-full w-20% md:w-50 avatars z-10">
        <UserControl v-if="auth.getAuthenticated" ></UserControl>
        <UserModal v-else-if="!auth.getAuthenticated"/>
      </div>
    </div>
    <div v-show="isShow" @click="isShow=false" class="fixed top-0 left-0 wh-full z-100 bg-gray-400 bg-opacity-50">
      <!-- 手机端导航栏 -->
      <nav  class="absolute top-12 flex items-center block flex-col md:h-18 h-18 mb-nav">
        <RouterLink :to="`/bbs`" class="nav_normal" active-class="nav_active">
          <div class="text-sm md:text-base lg:text-lg xl:text-2xl bold">综合</div>
        </RouterLink>
        <RouterLink :to="`/bbs/strategy`" class="nav_normal" active-class="nav_active">
          <div class="text-sm md:text-base lg:text-xl xl:text-2xl bold">攻略</div>
        </RouterLink>
        <RouterLink :to="`/bbs/information`" class="nav_normal " active-class="nav_active">
          <div class="text-sm md:text-base lg:text-lg xl:text-2xl bold">资讯</div>
        </RouterLink>
        <RouterLink :to="`/bbs/topic`" class="nav_normal" active-class="nav_active">
          <div class="text-sm md:text-base lg:text-lg xl:text-2xl bold">话题</div>
        </RouterLink>
      </nav>
    </div>
  </header>
  
</template>

<script setup lang="ts">
import { storeToRefs } from 'pinia';
import { fetchSearchTopic } from '@/server'
import logo from '@/assets/logo.png'

//router
const router = useRouter()
//工具store
const utilsStore = useUtilsStore()
const { skeletonLoading } = storeToRefs(utilsStore) //骨架屏渲染
//搜索文字
const searchStr = ref()
//文章store
const articleStore = useArticleStore()
//刷新等待时间
const loadingTime = 500
//手机端导航栏显示
const isShow = ref(false)


//搜索文章
const searchTopic = (str:any)=>{
  skeletonLoading.value = true
  if(str==undefined){
    str=''
  }
  
  fetchSearchTopic(str,()=>true).then((data)=>{
    router.push("/bbs")
    articleStore.setArticleList(data)
    setTimeout(() => {
      skeletonLoading.value = false
    }, loadingTime)
  })
}

const auth = useAuthStore()

</script>

<style scoped lang="scss">
@keyframes leftIn {
  from{
    left:-80vw
  }
  to{
    left:0;
  }
}
header{
  .mb-nav{
    width: 40vw;
    background-color: #fff;
    height: 80vh;
    a{
      width: 100%;
      height: auto;
 
      div{
        font-size: 1.075em;
        line-height: 2em;
      }
    }

    @media screen and (max-width:640px) {
      width: 70vw;
      animation: leftIn 0.5s;
    }
  }
    .a{
      aspect-ratio: 1/2;
    }
    .text-bg{
      background-color: azure;
      &:hover{
        background-color: rgb(22, 17, 17);
        color: #ccc;
      }
    }
    .avatars{

      img{
        height: 100%;
        object-fit: contain;
      }
    }
    .header-bg{
      position: relative;
      overflow: hidden;
      background: linear-gradient(to bottom, #c4e3f1, rgba(238, 255, 244, 0.876) );
      // filter:contrast(200%);
    }
    .header-bg::after {
      content: '';
      width: 50%;
      aspect-ratio: 2/1;
      background: linear-gradient(to bottom, #e7fef2, #dcedff, );
      animation: move_eye linear 15s infinite alternate;
      position: absolute;
      z-index: 1;
      mix-blend-mode: soft-light;
      filter: blur(30px);
      left: 0;
      top: center;
    }
    @keyframes move_eye {
      from {
        margin-left: -20%;
      }
  
      to {
        margin-left: 70%;
      }
    }

    .logo{
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      img{
        height: 70%;
        @media screen and (max-width:640px) {
          height: 84%;
        }
      }
    }
  }
.inputBox {

  width: 50px;
  height: 50px;
  position: relative;
  z-index: 999;
  
  @media screen and (max-width:640px) {
    width: 30px;
    height: 30px;
  }
  
}

.inputBox .search {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  background: #517bd6;
  border-radius: 50%;
  transition: all 1s;
  z-index: 4;
  box-shadow: 0 0 25px 0 rgba(0, 0, 0, 0.1);
  @media screen and (max-width:640px) {
    width: 36px;
    height: 36px;
  }
}

.inputBox .search:hover {
  cursor: pointer;
}

.inputBox .search::before {
  content: "";
  position: absolute;
  margin: auto;
  top: 18px;
  right: 0;
  bottom: 0;
  left: 18px;
  width: 10px;
  height: 2px;
  background: white;
  transform: rotate(45deg);
  transition: all .5s;
}

.inputBox .search::after {
  content: "";
  position: absolute;
  margin: auto;
  top: -3px;
  right: 0;
  bottom: 0;
  left: -3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid white;
  transition: all .5s;
}

.inputBox input {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  outline: none;
  border: none;
  background: rgb(43, 41, 41);
  color: rgb(230, 230, 230);
  border-radius: 30px;
  box-shadow: 0 0 25px 0 #6793f3, 0 0px 15px 0 rgba(219, 218, 218, 1);
  transition: all 0.5s;
  opacity: 0;
  z-index: 5;
  font-weight: bolder;
  font-size: 16px;
  @media screen and (max-width:640px) {
    width: 36px;
    height: 36px;
  }
}

.inputBox input:hover {
  cursor: pointer;
}

.inputBox input:focus {
  width: 300px;
  padding: 0 80px 0 20px;
  opacity: 1;
  cursor: text;
  border-radius:10px 30px 30px 10px;

  @media screen and (max-width:1280px){
    width: 250px;
    padding: 0 60px 0 20px;
  }
  @media screen and (max-width:640px){
    width: 220px;
    padding: 0 60px 0 20px;
  }
  @media screen and (max-width:480px){
    width: 190px;
    padding: 0 60px 0 20px;
  }
}

.inputBox input:focus~.search {
  right: 0px;
  background: #517bd6;
  z-index: 6;
}

.inputBox input:focus~.search::before {
  top: 0;
  left: 0;
  width: 25px;
}

.inputBox input:focus~.search::after {
  top: 0;
  left: 0;
  width: 25px;
  height: 2px;
  border: none;
  background: white;
  border-radius: 0%;
  transform: rotate(-45deg);
}

.inputBox input::placeholder {
  color: #777;
  opacity: 0.8;
}

.nav_active{
  color: #2775b6;
  background: rgb(242,242,242);
}
.nav_normal{
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  // width: 100%;
  height: inherit;
  padding: 0 1.8rem;
  font-size: 1.6rem;

  @media screen and (max-width:1024px) {
    padding: 0 1.4rem;
  }
  @media screen and (max-width:772px) {
    padding: 0 1rem;
  }
  @media screen and (max-width:640px) {
    padding: 0 0.6rem;
  }
  @media screen and (max-width:520px) {
    padding: 0 0.2rem;
  }
}
</style>




